/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uttt.edu.mx.datos;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import sun.nio.cs.HistoricallyNamedCharset;
import uttt.edu.mx.conexion.Conexion;
import uttt.edu.mx.entidades.EntCrearGrupo;

/**
 *
 * @author Jesus Santiago
 */
public class CtrlCrearGrupo implements IGeneral {

    private PreparedStatement st = null;
    private List<EntCrearGrupo> profe;
    private List<EntCrearGrupo> horario;
    private Connection conn;

    public boolean insertar1(EntCrearGrupo grupo) throws SQLException {
        try {
            Conexion datos = new Conexion();
            Connection conn = datos.getConexion();
            if (conn != null) {
                String query = "INSERT INTO grupo ( id_Nivel, horario, id_Persona ) "
                        + " VALUES ('" + grupo.getNivel()
                        + "' , '" + grupo.getIdHorario()
                        + "' , '" + grupo.getIdProfesor() + "');";
                st = conn.prepareStatement(query);
                int executeUpdate = st.executeUpdate();
                return true;
            } else {
                return false;
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            return false;
        }
    }

   
    public List<EntCrearGrupo> consultarP() throws SQLException {
        profe = new ArrayList<EntCrearGrupo>();
        Conexion datos = new Conexion();
        conn = datos.getConexion();
        st = (PreparedStatement) conn.prepareStatement("SELECT id_Persona, nombre FROM bd_highland.persona WHERE status = 'Academico';");
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            EntCrearGrupo grupo = new EntCrearGrupo();
            grupo.setIdProfesor(rs.getInt("id_Persona"));
            grupo.setProfesor(rs.getString("nombre"));
            profe.add(grupo);
        }
        return profe;
    }

    public List<EntCrearGrupo> consultarH() throws SQLException {
        horario = new ArrayList<EntCrearGrupo>();
        Conexion datos = new Conexion();
        conn = datos.getConexion();
        st = (PreparedStatement) conn.prepareStatement("SELECT id_Horario, descripcion FROM horario  ");
        ResultSet rs = st.executeQuery();

        while (rs.next()) {
            EntCrearGrupo grupo = new EntCrearGrupo();
            grupo.setIdHorario(rs.getInt("id_Horario"));
            grupo.setHorario(rs.getString("descripcion"));
            horario.add(grupo);
        }
        return horario;
    }

    @Override
    public boolean modificar(Object _Obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<Object> consultar(Object _Obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean insertar(Object _Obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean eliminar(Object _Obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
